package com.yonyou.pmclouds.personnel.service.rmiimpl;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.ref.itf.RefCodeConst;
import com.yonyou.pmclouds.basecom.ref.itf.ReferenceCheckOfBusiness;
import com.yonyou.pmclouds.personnel.entity.PersonnelVO;
import com.yonyou.pmclouds.personnel.rmiitf.PersonnelQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author chulf
 * @Date 2020/4/15
 * @Description 人员档案引用校验
 **/
@Component
public class ReferenceCheckOfPersonnel implements ReferenceCheckOfBusiness {

    @Autowired
    private PersonnelQuery personnelQuery;

    @Override
    public String[] getReferenceCode() {
        return new String[]{RefCodeConst.ENTERPRISE};
    }

    @Override
    public boolean checkReferenced(String bdCode, String[] keys) throws BusinessException {

        String code = null;
        if(RefCodeConst.ENTERPRISE.equals(bdCode)) {
            code = PersonnelVO.PK_ENTERPRISE;
        } else {
            throw new BusinessException("人员暂未引用该档案!");
        }
        return personnelQuery.queryPersonnelRef(code,keys);
    }
}
